package com.mathdroid.model.simulation;

import java.util.LinkedList;
import java.util.concurrent.TimeUnit;

/**
 * This contains the combat log for a single simulation.
 */
public final class CombatLog extends LinkedList<String> {

	/**
	 * Default UID.
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * Add an entry to the log and format it.
	 * @param timestamp The timestamp, when the event occurred.
	 * @param text What occurred.
	 */
	public void addEntry(final double timestamp, final String text) {
		
		final long minutes = TimeUnit.MILLISECONDS.toMinutes((long) timestamp);
		final long seconds = TimeUnit.MILLISECONDS.toSeconds((long) timestamp) 
								- TimeUnit.MINUTES.toSeconds(minutes);
		final long millis = (long) timestamp 
								- TimeUnit.MINUTES.toMillis(minutes) 
								- TimeUnit.SECONDS.toMillis(seconds);
		
		this.add("[" 
				+ String.format("%d:%d:%d", minutes, seconds, millis)
				+ "] " + text + "\n");
	}

	@Override
	public String toString() {
		String s = new String();
		
		for (String t : this) {
			s = s.concat(t);
		}
		
		return s;
	}
}
